package com.xiaoy.javamaildemo.formwork.javamail;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
import org.springframework.util.StopWatch;

import java.lang.reflect.Method;

/**
 * @ClassName MailInvocationHandler
 * @Description TODO
 * @Author xiaoying
 * @Date 2022/6/30 16:09
 * @Version V1.0.0
 */
@Slf4j
public class MailInvocationHandler implements MethodInterceptor {
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        StopWatch stopWatch = new StopWatch(method.getName());
        stopWatch.start();
        Object obj = methodProxy.invokeSuper(o,objects);
        stopWatch.stop();
        log.info("接口：{} 耗时：{} ms",method.getName(),stopWatch.getTotalTimeMillis());
        return obj;
    }
}
